package com.sizu.jxclog.web;

import com.sizu.common.entity.LogEntity;
import com.sizu.common.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class LogController {

    @Autowired
    private MongoTemplate mongoTemplate;

    @RequestMapping(value = "/log/add",method = RequestMethod.POST)
    public ResultEntity add(@RequestBody LogEntity logEntity){
        mongoTemplate.save(logEntity,"log");
        return ResultEntity.ok();
    }

    @RequestMapping(value = "/log/list",method = RequestMethod.GET)
    public ResultEntity list(){
        List<LogEntity> logEntityList = mongoTemplate.findAll(LogEntity.class,"log");
        return ResultEntity.ok(logEntityList);
    }
}
